package com.ss.expression;

import com.ss.dto.LoginUserDto;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("customExpressionRoot")
public class CustomExpressionRoot {

    public boolean hasAuthority(String role){
         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
         LoginUserDto loginUserDto = (LoginUserDto) authentication.getPrincipal();
         List<String> permissions = loginUserDto.getPermissions();
        return permissions.contains(role);
    }

}
